<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//Route::get('/','PagesController@root')->name('root');
Route::redirect('/', '/products')->name('root');
Route::get('products', 'ProductsController@index')->name('products.index');
//Route::get('products/{product}', 'ProductsController@show')->name('products.show');
Auth::routes();
Route::group(['middleware'=>'auth'],function(){
    Route::get('/email_verify_notice','PagesController@emailVerifyNotice')->name('email_verify_notice');
    Route::group(['middleware' => 'email_verified'], function() {
        Route::get('user_addresses','UserAddressesController@index')->name('user_addresses.index');
        Route::get('user_addresses/create','UserAddressesController@create')->name('user_addresses.create');
        Route::post('user_addresses', 'UserAddressesController@store')->name('user_addresses.store');
        Route::get('user_addresses/{user_address}','UserAddressesController@edit')->name('user_addresses.edit');
        Route::put('user_addresses/{user_address}','UserAddressesController@update')->name('user_addresses.update');
        Route::delete('user_addresses/{user_address}','UserAddressesController@destroy')->name('user_addresses.destroy');
        Route::get('products/favorites', 'ProductsController@favorites')->name('products.favorites');
        Route::post('products/{product}/favorite', 'ProductsController@favor')->name('products.favor');
        Route::delete('products/{product}/favorite', 'ProductsController@disfavor')->name('products.disfavor');

        Route::get('cart','CartController@index')->name('cart.index');
        Route::post('cart','CartController@add')->name('cart.add');
        Route::delete('cart/{sku}','CartController@remove')->name('cart.remove');


        Route::post('orders','OrdersController@store')->name('orders.store');
        Route::get('orders','OrdersController@index')->name('orders.index');
        Route::get('orders/{order}','OrdersController@show')->name('orders.show');
        Route::post('orders/{order}/received','OrdersController@received')->name('orders.received');

        //支付宝支付路由
        Route::get('payment/{order}/alipay','PaymentController@payByAlipay')->name('payment.alipay');
        Route::get('payment/alipay/return', 'PaymentController@alipayReturn')->name('payment.alipay.return');
        //微信支付
        Route::get('payment/{order}/wechat', 'PaymentController@payByWechat')->name('payment.wechat');
    });
    Route::get('/email_verification/verify','EmailVerificationController@verify')->name('email_verification.verify');
    Route::get('/email_verification/send','EmailVerificationController@send')->name('email_verification.send');
});
//支付宝支付的回调
Route::get('products/{product}', 'ProductsController@show')->name('products.show');
//微信支付的回调
Route::post('payment/wechat/notify', 'PaymentController@wechatNotify')->name('payment.wechat.notify');
//支付宝支付测试路由
//Route::get('alipay', function() {
//    return app('alipay')->web([
//        'out_trade_no' => time(),
//        'total_amount' => '1',
//        'subject' => 'test subject - 测试',
//    ]);
//});
Route::post('payment/alipay/notify', 'PaymentController@alipayNotify')->name('payment.alipay.notify');
